include ../Makefile.Res

all:license.tgz register.tar.gz

license.tgz:libinfo.a serial Register license initor encode server client
	rm -rf usr && mkdir -p usr/sbin/ usr/etc/
	cp serial license initor client usr/sbin/ -rf
	echo 0 > usr/etc/license
	tar czvf license.tgz usr

register.tar.gz:server cacert.pem privkey.pem
	rm -rf usr && mkdir -p usr/sbin/
	cp server usr/sbin/register_server -rf
	cp *.pem usr/sbin/ -rf
	cp README.register usr/sbin/ -rf 
	tar czf register.tar.gz usr

server:server.c pidfile.h
	gcc -Wall -lssl server.c -o server -O2 pidfile.c
	strip server 
	rm -rf Server && mkdir Server
	cp -rf *.pem server Server 
	tar czvf server.tar.gz Server
client:client.c md5.o mac.o
	gcc -Wall client.c -o client md5.o mac.o -O3 -lssl -lcrypto  libinfo.a
	strip client

encode:encode.c
	gcc -O3 encode.c -Wall -o encode
	strip encode
	cp -rf encode /bin/

libinfo.a:dmidecode-2.9.tar.gz
	rm -rf dmidecode-2.9
	tar xzvf dmidecode-2.9.tar.gz
	patch -p0 < dev_patch
	make -C dmidecode-2.9
	cp dmidecode-2.9/libinfo.a ./

get_info.o:get_info.c
	gcc -c get_info.c -Wall

serial:serial.c mac.o md5.o get_info.o
	gcc -Wall -o serial serial.c md5.o mac.o -O3 -lssl -lcrypto get_info.o libinfo.a
	strip serial

license:input_license.c 
	gcc input_license.c -Wall -o license -O3
	strip license
	
Register:register.c md5.o get_time.o openssl.o register.h
	gcc register.c -lssl -Wall md5.o  -o Register -O3 -lcrypto get_time.o openssl.o
	cp Register /usr/bin/ -rf
	strip Register

initor:init_env.c shmem_pub.o get_time.o md5.o mac.o openssl.o
	gcc init_env.c -lssl -Wall md5.o  -o initor -O3 mac.o -lcrypto \
	get_info.o libinfo.a shmem_pub.o get_time.o openssl.o
	strip initor

mac.o:get_mac.c get_mac.h
	gcc -Wall get_mac.c -o mac.o -c -O3

md5.o:get_md5.c get_md5.h
	gcc -Wall get_md5.c  -o md5.o -c -O3

get_time.o:get_time.c get_time.h
	gcc -Wall get_time.c  -o get_time.o -c -O3

shmem_pub.o:shmem_pub.c shmem_pub.h
	gcc -Wall shmem_pub.c -o shmem_pub.o -c -O3

shm_test: shm_test.c 
	gcc shm_test.c  -Wall -o shm_test -O3  shmem_pub.o
	
clean:
	rm -rf *.o serial license Register initor *_test usr *.tgz  *.a tags server client a.out \
	encode dmidecode-2.9

dist_clean:clean
	rm -rf dmidecode-2.9 *.tar.gz Server
